﻿using System.IO;
using System.Xml.Serialization;

namespace Excuse.Models
{
    public class LicenseModel
    {
        /// <summary>
        /// 0 : Free
        /// 1 : Niveau 1
        /// 2 : Niveau 2
        /// 3 : Niveau 3
        /// 4 : Niveau 4
        /// </summary>
        public int LevelType { get; set; }

        /// <summary>
        /// User + Value + Option
        /// </summary>
        public string Id { get; set; }

        public string Value { get; set; }

        public string Option { get; set; }

        #region Methods

        public override string ToString()
        {
            return this.ToXmlString();
        }

        public void SetId()
        {
            Id = string.Format("iuoiu{0}fdfs{1}ssdf{2}ssfsfeewrw", LevelType, Value, Option);
        }

        #endregion
    }

    public static class XmlTools
    {
        public static string ToXmlString<T>(this T input)
        {
            using (var writer = new StringWriter())
            {
                input.ToXml(writer);
                return writer.ToString();
            }
        }
        public static void ToXml<T>(this T objectToSerialize, Stream stream)
        {
            new XmlSerializer(typeof(T)).Serialize(stream, objectToSerialize);
        }

        public static void ToXml<T>(this T objectToSerialize, StringWriter writer)
        {
            new XmlSerializer(typeof(T)).Serialize(writer, objectToSerialize);
        }
    }
}